<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>composition API-练习</title>
  <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
  <div id="root"></div>
</body>
<script>
	// list 内容封装
  const listRelativeEffect = (item)=>{
		const { reactive } = Vue;
		const valueList = reactive([])
		const addItemToList = (item) =>{
			valueList.push(item)
		}
		return {
			valueList,
			addItemToList
		}
	}

	// inputValue 操作封装
	const inputRelativeEffect = () =>{
		const { ref } = Vue;
		const inputValue = ref('');
		const handleInputValueChange = (e)=>{
			inputValue.value = e.target.value
		}
		return {
			inputValue,
			handleInputValueChange
		}
	}
  const app = Vue.createApp({
    template: `
		<div>
			<input :value='inputValue' @input='handleInputValueChange'/>
			<button @click="()=> addItemToList(inputValue)">提交</button>
		</div>
    <ul>
			<li v-for="(item,index) in valueList" :key='index'>{{item}}</li>
		</ul>

    `,
		setup(props,context) {
			const { valueList, addItemToList} = listRelativeEffect()
			const { inputValue, handleInputValueChange} = inputRelativeEffect()
	
			return {
				valueList,	addItemToList,
				inputValue,handleInputValueChange		
			}
		}
  });
  const vm = app.mount('#root');
</script>
</html>